﻿//自动转行函数, encStr为实体转换后的字符串,如abc&#34;:ds&#39;&#60;!!!!!?&#62;&#47;&#92;@#$%
function insertWbr(encStr, len) {
    var ta = document.createElement('textarea');
    ta.innerHTML = encStr;
    document.body.appendChild(ta);

    var rsStr = ta.value; rsStr = rsStr.replace(new RegExp("(\\S{" + len + "})", "img"), "$1<wbr>");
    document.body.removeChild(ta);
    rsStr = rsStr.replace(/<wbr>/g, "\u0001");
    rsStr = rsStr.replace(/</g, "&lt;");
    rsStr = rsStr.replace(/>/g, "&gt;");
    rsStr = rsStr.replace(/\u0001/g, "<wbr>");

    return rsStr;
}

function JsLoader() {
    this.load = function(url) {
        var ss = document.getElementsByTagName("script");
        for (i = 0; i < ss.length; i++) {
            if (ss[i].src && ss[i].src.indexOf(url) != -1) {
                this.onsuccess();
                return;
            }
        }
        s = document.createElement("script");
        s.type = "text/javascript";
        s.src = url;
        var head = document.getElementsByTagName("head")[0];
        head.appendChild(s);
        var self = this;
        s.onload = s.onreadystatechange = function() {
            if (this.readyState && this.readyState == "loading")
                return;
            self.onsuccess();
        }
        s.onerror = function() {
            head.removeChild(s);
            self.onfailure();
        }
    };

    this.onsuccess = function() { };
    this.onfailure = function() { };
}

/* 使用方法
var myJs = new JsLoader();
myJs.onsuccess = function() { //设置信息
    //在这里可以写程序
}
myJs.load(baseURL);
*/